package zhu.areas.team.action;

import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import zhu.areas.dic.data.TeamAuState;
import zhu.areas.dic.data.TeamField;
import zhu.areas.dic.data.TeamPubType;
import zhu.areas.dic.data.TeamRole;
import zhu.areas.team.data.Team;
import zhu.areas.team.data.TeamMembers;
import zhu.areas.team.data.TeamNotice;
import zhu.areas.team.service.ITeamZhService;
import zhu.common.service.IDicService;

import com.opensymphony.xwork2.ActionSupport;

//团队管理中团队维护子模块
public class TeamZhAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private int teamID;
	private int teamFounderID;
	private String teamName;
	private TeamField teamNowField;
	private TeamField teamGoalField;
	private String teamLevel;
	private int teamExp;
	private Date regDate;
	private String teamSlogan;
	private TeamAuState teamAuState;
	private String teamLogo; 

	private int teamMID;
	private int userID;
	private TeamRole teamRoleID;
	

	private int noticeID;
	private int pubUserID;
	private String teamPubTitle;
	private String teamPubContent;
	private Date teamPubTime;
	private TeamPubType teamPubType;
	

	private Team team;
	private TeamNotice teamNotice;
	private TeamMembers teamMembers;
	private List<TeamMembers> teamMemberslist;
	private ITeamZhService teamZhService;

	private IDicService dicService;


	// 通过ID查找团队
	public String findTeam() {
		teamID = (Integer) ServletActionContext.getRequest().getSession().getAttribute("teamID");
		team = this.teamZhService.findByTeamId("TeamID", teamID);
		if(team.getTeamstatue().getTeamAuStateID()!=3){
			return ERROR;
		}
		teamMemberslist = this.teamZhService.findMembersByTeamId("TeamID", teamID);
		teamNotice = this.teamZhService.findTopNoticeByTeamId("TeamID", teamID);		
		TeamNoticeToconvert();
		TeamToconvert();
		return SUCCESS;
	}

	// 将数据库查找的团队信息转换成页面输出信息
	public void TeamNoticeToconvert(){
		this.pubUserID = teamNotice.getPubUserID();
		this.teamPubTitle = teamNotice.getTeamPubTitle();
		this.teamPubTime = teamNotice.getTeamPubTime();
	}
	public void TeamToconvert() {
		this.teamID = team.getTeamID();
		this.teamName = team.getTeamName();
		this.teamFounderID = team.getTeamFounderID();
		this.teamExp = team.getTeamExp();
		this.teamLevel = team.getTeamLevel();
		this.regDate = team.getRegDate();
		this.teamSlogan = team.getTeamSlogan();
		this.teamLogo = team.getTeamLogo();
		this.teamAuState = team.getTeamstatue();
	}
	// 将页面输入信息转换成team对象
	public void ConvertToteam(){
		team.setTeamID(this.teamID);
		team.setTeamFounderID(this.teamFounderID);
		team.setTeamSlogan(this.teamSlogan);
		team.setTeamName(this.teamName);
		team.setRegDate(this.regDate);
		team.setTeamLevel(this.teamLevel);
		team.setTeamExp(this.teamExp);
		team.setTeamLogo(this.teamLogo);
	
	}

	// 跳到团队查找页面
	public String index() {
		return SUCCESS;
	}
	//跳到修改团队信息页面
	public String tomodityteaminfo(){
		return SUCCESS;
	}

	// 修改团队信息
	public String updateteaminfo() {
		this.ConvertToteam();
		this.teamZhService.saveOrUpdateteaminfo(team);
		return SUCCESS;
	}
	//解散团队
	public String deleteteam(){
		team = this.teamZhService.findByTeamId("TeamID", teamID);
		teamMemberslist = this.teamZhService.findMembersByTeamId("TeamID", teamID);
		if(teamMemberslist.size()==1){
		this.teamZhService.deleteteam(team);
		}
		return SUCCESS;
	}
	//跳转到发布公告页面
	public String topubtnotice(){
		return SUCCESS;
	}
	//发布公告
	public String pubteamnotice(){
		teamNotice=new TeamNotice();
     	this.ConvertToteamNotice();	
		this.teamZhService.savepubteamnotice(teamNotice);		
		return SUCCESS;
	}
	//将页面输入信息转换成公告对象信息
	public void ConvertToteamNotice(){		
		teamNotice.setTeamID(this.teamID);
		teamNotice.setTeamName(this.teamName);
		teamNotice.setTeamPubContent(this.teamPubContent);
		teamNotice.setTeamPubTitle(this.teamPubTitle);
		teamNotice.setTeamPubTime(new Date());
	}
	
	//查找团队成员
	public String findteammembers(){
		
		teamMemberslist = this.teamZhService.findMembersByTeamId("TeamID", teamID);
		
		System.out.println(teamID);
		for(int i=0;i<teamMemberslist.size();i++){
			System.out.println(teamMemberslist.get(i).getUserID());
		}
		return SUCCESS;
	}

	public int getTeamID() {
		return teamID;
	}

	public void setTeamID(int teamID) {
		this.teamID = teamID;
	}

	public int getTeamFounderID() {
		return teamFounderID;
	}

	public void setTeamFounderID(int teamFounderID) {
		this.teamFounderID = teamFounderID;
	}

	public String getTeamName() {
		return teamName;
	}

	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}

	public TeamField getTeamNowField() {
		return teamNowField;
	}

	public void setTeamNowField(TeamField teamNowField) {
		this.teamNowField = teamNowField;
	}

	public TeamField getTeamGoalField() {
		return teamGoalField;
	}

	public void setTeamGoalField(TeamField teamGoalField) {
		this.teamGoalField = teamGoalField;
	}

	public String getTeamLevel() {
		return teamLevel;
	}

	public void setTeamLevel(String teamLevel) {
		this.teamLevel = teamLevel;
	}

	public int getTeamExp() {
		return teamExp;
	}

	public void setTeamExp(int teamExp) {
		this.teamExp = teamExp;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public String getTeamSlogan() {
		return teamSlogan;
	}

	public void setTeamSlogan(String teamSlogan) {
		this.teamSlogan = teamSlogan;
	}

	public TeamAuState getTeamAuState() {
		return teamAuState;
	}

	public void setTeamAuState(TeamAuState teamAuState) {
		this.teamAuState = teamAuState;
	}

	public String getTeamLogo() {
		return teamLogo;
	}

	public void setTeamLogo(String teamLogo) {
		this.teamLogo = teamLogo;
	}

	public int getTeamMID() {
		return teamMID;
	}

	public void setTeamMID(int teamMID) {
		this.teamMID = teamMID;
	}

	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	public TeamRole getTeamRoleID() {
		return teamRoleID;
	}

	public void setTeamRoleID(TeamRole teamRoleID) {
		this.teamRoleID = teamRoleID;
	}

	public int getNoticeID() {
		return noticeID;
	}

	public void setNoticeID(int noticeID) {
		this.noticeID = noticeID;
	}

	public int getPubUserID() {
		return pubUserID;
	}

	public void setPubUserID(int pubUserID) {
		this.pubUserID = pubUserID;
	}

	public String getTeamPubTitle() {
		return teamPubTitle;
	}

	public void setTeamPubTitle(String teamPubTitle) {
		this.teamPubTitle = teamPubTitle;
	}

	public String getTeamPubContent() {
		return teamPubContent;
	}

	public void setTeamPubContent(String teamPubContent) {
		this.teamPubContent = teamPubContent;
	}

	public Date getTeamPubTime() {
		return teamPubTime;
	}

	public void setTeamPubTime(Date teamPubTime) {
		this.teamPubTime = teamPubTime;
	}

	public TeamPubType getTeamPubType() {
		return teamPubType;
	}

	public void setTeamPubType(TeamPubType teamPubType) {
		this.teamPubType = teamPubType;
	}

	public Team getTeam() {
		return team;
	}

	public void setTeam(Team team) {
		this.team = team;
	}

	public TeamNotice getTeamNotice() {
		return teamNotice;
	}

	public void setTeamNotice(TeamNotice teamNotice) {
		this.teamNotice = teamNotice;
	}

	public TeamMembers getTeamMembers() {
		return teamMembers;
	}

	public void setTeamMembers(TeamMembers teamMembers) {
		this.teamMembers = teamMembers;
	}

	public List<TeamMembers> getTeamMemberslist() {
		return teamMemberslist;
	}

	public void setTeamMemberslist(List<TeamMembers> teamMemberslist) {
		this.teamMemberslist = teamMemberslist;
	}

	public ITeamZhService getTeamZhService() {
		return teamZhService;
	}

	public void setTeamZhService(ITeamZhService teamZhService) {
		this.teamZhService = teamZhService;
	}

	public IDicService getDicService() {
		return dicService;
	}

	public void setDicService(IDicService dicService) {
		this.dicService = dicService;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}



	
}
